package com.hotel.BL;

import java.util.ArrayList;
import java.util.List;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.CompositeFilterOperator;
import com.google.appengine.api.datastore.Query.Filter;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.FilterPredicate;

import data.HotelCustomSetting;

public class HotelCustomSettingLogic extends AbstractBL{
	public List<HotelCustomSetting> GenerateHotelCustomSetting(long hotelId)
	{
		List<HotelCustomSetting> list = new ArrayList<HotelCustomSetting>();
		
		HotelCustomSetting hotelcustomsetting;
		if(GetHotelCustomSettingType(1,null) == null){
			hotelcustomsetting = new HotelCustomSetting();
			hotelcustomsetting.setHotelId(hotelId);
			hotelcustomsetting.setAddTax(false);
			hotelcustomsetting.setAllowGenOfTranToRoom(false);
			hotelcustomsetting.setBillingInvoice(false);
			hotelcustomsetting.setBookingConfirmationHeaders(false);
			hotelcustomsetting.setCalculateWebBookingPolicy(false);
			hotelcustomsetting.setCurrencyRate(false);
			hotelcustomsetting.setEmailID("test@gmail.com");
			hotelcustomsetting.setEnableMultiLanguage(false);
			hotelcustomsetting.setEnhancedLedger(false);
			hotelcustomsetting.setGetFullCrddetailsInBookingNotification(false);
			hotelcustomsetting.setGetFullCreditCard(false);
			hotelcustomsetting.setHideDiscAllw(false);
			hotelcustomsetting.setHotelId(hotelId);
			hotelcustomsetting.setPaymentGatewayRefund(false);
			hotelcustomsetting.setPOSFolioInclusiveOfTax(false);
			hotelcustomsetting.setReviewExpress(false);
			hotelcustomsetting.setShowBookingAmountAccStateFolio(false);
			hotelcustomsetting.setShowBookingAmountBalance(false);
			hotelcustomsetting.setShowCustomReservationFolio(false);
			hotelcustomsetting.setShowOnlyTotalAmountPOS(false);
			hotelcustomsetting.setShowQuickView(false);
			hotelcustomsetting.setShowRatesOfTheDay(false);
			hotelcustomsetting.setUseInMailChimpSubscriber(false);
			hotelcustomsetting.setViewLocatorDetailsOnFront(false);
			list.add(hotelcustomsetting);
		}
		return list;
	}
	
	public HotelCustomSetting GetHotelCustomSettingType(long hotelId,String title)
	{
		Query q = new Query(EntityName.HotelCustomSetting);
		Filter filterHotel = new FilterPredicate("hotelId",FilterOperator.EQUAL,hotelId);
		Filter filterStatus = new FilterPredicate("status",FilterOperator.EQUAL,true);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterTitle = new FilterPredicate("EmailID",FilterOperator.NOT_EQUAL,title);
		Filter filter = CompositeFilterOperator.and(filterHotel, filterStatus, filterAvaliable,filterTitle);
		q.setFilter(filter);
		
		return GetHotelCustomSetting(datastore.prepare(q).asSingleEntity());
	}
	
	public HotelCustomSetting GetHotelCustomSetting(Entity entity)
	{
		if(entity == null) return null;
		HotelCustomSetting item = new HotelCustomSetting();
		item.setEntity(entity);
		return item;
	}
	
	public List<HotelCustomSetting> GetHotelCustomSettingAll(long hotelId) {
		Query q = new Query(EntityName.HotelCustomSetting);
		Filter filterHotel = new FilterPredicate("hotelId",FilterOperator.EQUAL,hotelId);
		q.setFilter(filterHotel);
		return GetHotelCustomSettingList(datastore.prepare(q).asList(
				FetchOptions.Builder.withDefaults()));
	}
	
	public List<HotelCustomSetting> GetHotelCustomSettingList(List<Entity> entities)
	{
		List<HotelCustomSetting> list = new ArrayList<HotelCustomSetting>();
		if(entities!=null)
			for(Entity e : entities)
			{
				HotelCustomSetting a = new HotelCustomSetting();
				a.setEntity(e);
				list.add(a);
			}
		return list;
	}
}
